package com.jiang.专题.数组.Q349;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/03/04 13:45
 */
class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            set1.add(nums1[i]);
        }

        for (int i = 0; i < nums2.length; i++) {
            if (set1.contains(nums2[i]))
                set2.add(nums2[i]);
        }

        return set2.stream().mapToInt(Integer::valueOf).toArray();
    }
}
